//-----------------------------------------------------------------------
// <copyright file="a_SEO_SettingDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_SEO_SettingDAOBase
    {
        #region Common methods
        public virtual a_SEO_Setting Createa_SEO_SettingFromReader(IDataReader reader)
        {
            a_SEO_Setting item = new a_SEO_Setting();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("SID"))) item.SID = (int)reader["SID"];
                if (!reader.IsDBNull(reader.GetOrdinal("PageElements"))) item.PageElements = (string)reader["PageElements"];
                if (!reader.IsDBNull(reader.GetOrdinal("MaxWords"))) item.MaxWords = (int)reader["MaxWords"];
                if (!reader.IsDBNull(reader.GetOrdinal("MaxChars"))) item.MaxChars = (int)reader["MaxChars"];
                if (!reader.IsDBNull(reader.GetOrdinal("TargetDensity"))) item.TargetDensity = (decimal)reader["TargetDensity"];
                if (!reader.IsDBNull(reader.GetOrdinal("Row"))) item.Row = (byte)reader["Row"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_SEO_Setting methods
            
        public virtual void Createa_SEO_Setting(a_SEO_Setting a_SEO_Setting)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Settings_ins");
                
                database.AddInParameter(dbCommand, "@PageElements", DbType.AnsiString, a_SEO_Setting.PageElements);
                database.AddInParameter(dbCommand, "@MaxWords", DbType.Int32, a_SEO_Setting.MaxWords);
                database.AddInParameter(dbCommand, "@MaxChars", DbType.Int32, a_SEO_Setting.MaxChars);
                database.AddInParameter(dbCommand, "@TargetDensity", DbType.Currency, a_SEO_Setting.TargetDensity);
                database.AddInParameter(dbCommand, "@Row", DbType.Byte, a_SEO_Setting.Row);
                database.AddOutParameter(dbCommand, "@SID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_SEO_Setting.SID = (int)database.GetParameterValue(dbCommand, "@SID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_SEO_Setting methods
        
        public virtual void Updatea_SEO_Setting(a_SEO_Setting a_SEO_Setting)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Settings_upd");            
                
                database.AddInParameter(dbCommand, "@SID", DbType.Int32, a_SEO_Setting.SID);
                database.AddInParameter(dbCommand, "@PageElements", DbType.AnsiString, a_SEO_Setting.PageElements);
                database.AddInParameter(dbCommand, "@MaxWords", DbType.Int32, a_SEO_Setting.MaxWords);
                database.AddInParameter(dbCommand, "@MaxChars", DbType.Int32, a_SEO_Setting.MaxChars);
                database.AddInParameter(dbCommand, "@TargetDensity", DbType.Currency, a_SEO_Setting.TargetDensity);
                database.AddInParameter(dbCommand, "@Row", DbType.Byte, a_SEO_Setting.Row);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_SEO_Setting methods
        public virtual void Deletea_SEO_Setting(int sid)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Settings_del");
                
                database.AddInParameter(dbCommand, "@SID", DbType.Int32, sid);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_SEO_Setting methods
        
        public virtual a_SEO_Setting Geta_SEO_Setting(int sid)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Settings_sel");
                
                database.AddInParameter(dbCommand, "@SID", DbType.Int32, sid);
                
                a_SEO_Setting a_SEO_Setting =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_SEO_Setting = Createa_SEO_SettingFromReader(reader);
                        reader.Close();
                    }
                }
                return a_SEO_Setting;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_SEO_SettingList methods
        public virtual a_SEO_SettingCollection Geta_SEO_SettingList(a_SEO_SettingColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Settings_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_SEO_SettingCollection a_SEO_SettingCollection = new a_SEO_SettingCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_SEO_Setting a_SEO_Setting = Createa_SEO_SettingFromReader(reader);
                        a_SEO_SettingCollection.Add(a_SEO_Setting);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_SEO_SettingCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_SEO_SettingCollection Geta_SEO_SettingList(a_SEO_SettingColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_SEO_SettingList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}